library dialog_loading;

import 'package:flutter/material.dart';
import 'package:flutter_jpf_core/util/colors_util.dart';

// ignore: must_be_immutable
class DialogLoading extends StatelessWidget {
  BuildContext context;
  bool isShowing = false;

  DialogLoading(BuildContext _context) {
    this.context = _context;
  }

  void hideLoading() {
    if(isShowing) {
      Navigator.of(context).pop();
      isShowing = false;
    }
  }

  void showLoading({String msg = "请稍等..."}) {
    if(!isShowing) {
      showDialog<void>(
          context: context,
          barrierDismissible: false,
          builder: (BuildContext context){
            return new WillPopScope(
              onWillPop: () async => false,
              child: new Dialog(
                  child: Container(
                      child: Row(children: <Widget>[
                        Container(
                            padding: EdgeInsets.fromLTRB(15, 15, 20, 15),
                            child: CircularProgressIndicator(
                                strokeWidth: 2,
                                valueColor: AlwaysStoppedAnimation<Color>(Colors.deepOrange), backgroundColor: Colors.white)
                        ),
                        Text(msg, style: TextStyle(
                            color: ColorsUtil.black_333,
                            fontSize: 15,
                            fontWeight: FontWeight.w600
                        ))
                      ])
                  )
              )
            );
          }
      );
      isShowing = true;
    }
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
  }
}
